package com.bwie.commodity.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.bwie.commodity.domain.CommodityType;
import com.bwie.commodity.domain.dto.CommodityTypeAttributesDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bwie.common.log.annotation.Log;
import com.bwie.common.log.enums.BusinessType;
import com.bwie.common.security.annotation.RequiresPermissions;
import com.bwie.commodity.domain.CommodityTypeAttributes;
import com.bwie.commodity.service.ICommodityTypeAttributesService;
import com.bwie.common.core.web.controller.BaseController;
import com.bwie.common.core.web.domain.AjaxResult;
import com.bwie.common.core.utils.poi.ExcelUtil;
import com.bwie.common.core.web.page.TableDataInfo;

/**
 * 属性/参数列表Controller
 *
 * @author ruoyi
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/attributes")
public class CommodityTypeAttributesController extends BaseController
{
    @Autowired
    private ICommodityTypeAttributesService commodityTypeAttributesService;

    @Autowired
    private CommodityTypeController commodityTypeController;

    /**
     * 查询属性/参数列表列表
     */
    @RequiresPermissions("commodity:attributes:list")
    @GetMapping("/list")
    public TableDataInfo list(CommodityTypeAttributes commodityTypeAttributes)
    {
        startPage();
        List<CommodityTypeAttributes> list = commodityTypeAttributesService.selectCommodityTypeAttributesList(commodityTypeAttributes);
        return getDataTable(list);
    }

    /**
     * 导出属性/参数列表列表
     */
    @RequiresPermissions("commodity:attributes:export")
    @Log(title = "属性/参数列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityTypeAttributes commodityTypeAttributes)
    {
        List<CommodityTypeAttributes> list = commodityTypeAttributesService.selectCommodityTypeAttributesList(commodityTypeAttributes);
        ExcelUtil<CommodityTypeAttributes> util = new ExcelUtil<CommodityTypeAttributes>(CommodityTypeAttributes.class);
        util.exportExcel((jakarta.servlet.http.HttpServletResponse) response, list, "属性/参数列表数据");
    }

    /**
     * 获取属性/参数列表详细信息
     */
    @RequiresPermissions("commodity:attributes:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commodityTypeAttributesService.selectCommodityTypeAttributesById(id));
    }

    /**
     * 新增属性/参数列表
     */
    @RequiresPermissions("commodity:attributes:add")
    @Log(title = "属性/参数列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityTypeAttributes commodityTypeAttributes)
    {
        return toAjax(commodityTypeAttributesService.insertCommodityTypeAttributes(commodityTypeAttributes));
    }

    /**
     * 修改属性/参数列表
     */
    @RequiresPermissions("commodity:attributes:edit")
    @Log(title = "属性/参数列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityTypeAttributes commodityTypeAttributes)
    {
        return toAjax(commodityTypeAttributesService.updateCommodityTypeAttributes(commodityTypeAttributes));
    }

    /**
     * 删除属性/参数列表
     */
    @RequiresPermissions("commodity:attributes:remove")
    @Log(title = "属性/参数列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commodityTypeAttributesService.deleteCommodityTypeAttributesByIds(ids));
    }

    /**
     * 查询筛选属性
     */
    @RequiresPermissions("commodity:attributes:getAttributesTree")
    @GetMapping("/getAttributesTree")
    public AjaxResult getAttributesTree()
    {
        List<CommodityTypeAttributesDTO> list = commodityTypeAttributesService.getAttributesTree();
        return success(list);
    }

    /**
     * 查询属性列表
     * @return
     */
    @RequiresPermissions("commodity:attributes:getAttrByType")
    @GetMapping("/getAttrByType")
    public AjaxResult getAttrByType()
    {
        List<CommodityTypeAttributes> list = commodityTypeAttributesService.getAttrByType();
        return success(list);
    }

}
